<table id="jdBaseInfo_data"></table>
<script>
	$(function(){
		$.post("../jdBaseInfoServletBack?t="+new Date(),{op:"getAllThemeInfo"},function(data){
			var datagrid;
			var editRow=undefined;
			var op;
			datagrid=$('#jdBaseInfo_data').datagrid({   
		    url:'../jdBaseInfoServletBack',
		    queryParams:{op:"getJdBaseInfo"}, 
		    loadMsg:'努力加载数据中...',
		    fitColumns:true,
		    fit:true,
		    striped:true,
		    pagination:true,
		    pagePosition:'both',
		    rownumbers:true,
		    sortName:'jbid',
		    sortOrder:'asc',
		    remoteSort:false,
		    pageNumber:1,
		    pageSize:10,
		   	pageList:[10,20,30,40,50],	     
		    columns:[[   
		    	{field:'flag',title:'',checkbox:true,width:100,align:'center'},   
		        {field:'jbid',title:'编号',width:100,align:'center',sortable:true},   
		        {field:'jname',title:'景点名',width:200,align:'center',sortable:true,editor:{type:'text',options:{requeired:true}}}, 
		        {field:'city',title:'所在城市',width:100,align:'center',sortable:true,editor:{type:'text',options:{requeired:true}}},    
		        {field:'price',title:'票面价',width:100,align:'center',sortable:true,editor:{type:'numberbox',options:{min:0,max:9999999,precision:2,requeired:true}}},    
		        {field:'act',title:'票折扣',width:100,align:'center',sortable:true,editor:{type:'numberbox',options:{min:0,max:1,precision:2,requeired:true}}},    
		        {field:'temp',title:'同程价',width:100,align:'center',sortable:true},    
		        {field:'jtid',title:'主题类型',width:100,align:'center',sortable:true,editor:{type:'combobox',options:{required:true,valueField:'jtid',textField:'tname',data:data.JdThemeInfo }},
		        	formatter:function(value,row,index){
		        		for(var i=0;i<data.JdThemeInfo.length;i++){
		        			if(data.JdThemeInfo[i].jtid==value){
		        				return data.JdThemeInfo[i].tname;
		        			}
		        		}
		        		return value;
		        	}	
		        }   
		    ]],
		    toolbar: [{
		    	text:'添加',
				iconCls: 'icon-add',
				handler: function(){
					op="addJdBaseInfo";
					if(editRow!=undefined){  
						datagrid.datagrid("rejectChanges");
						datagrid.datagrid('endEdit', editRow );  
						editRow=undefined;
					}				
					if(editRow==undefined){
						datagrid.datagrid('insertRow',{index:0,row:{}});
						datagrid.datagrid("beginEdit",0);
						editRow=0;  
					}
				}
			},'-',{
					text:'删除',
					iconCls: 'icon-remove',
					handler: function(){
						var rows=$('#jdBaseInfo_data').datagrid("getChecked")[0];
						if(rows==undefined){
							$.messager.show({title:'温馨提示',msg:'请选择要删除的数据...',timeout:3000,showType:'slide'});
						}else{
							$.messager.confirm('信息确认', '您确定要删除选中的记录吗?', function(r){
								if (r){
									op="delJdBaseInfo";
									var jbids="";
									var st=datagrid.datagrid("getSelections").length;
									
									for(var j=0;j<st-1;j++){
										jbids+=datagrid.datagrid("getSelections")[j].jbid+",";
									}
									jbids+=datagrid.datagrid("getSelections")[j].jbid;

									$.post("../jdBaseInfoServletBack?t="+new Date(),{op:"delJdBaseInfo",jbids:jbids},function(data){
										data=parseInt($.trim(data));
										if(data>0){
											$.messager.show({title:'成功提示',msg:'信息删除成功...',timeout:3000,showType:'slide'});
											$('#jdBaseInfo_data').datagrid("reload");
										}else{
											$.messager.alert('失败提示','删除失败，请确保该项不含任何子记录...','error');
											$('#jdBaseInfo_data').datagrid("reload");
										}
									});
								}
										
							});
						}
					}
				},'-',{
			    	text:'修改',
					iconCls: 'icon-edit',
					handler: function(){
						var rows=$('#jdBaseInfo_data').datagrid("getChecked")[0];
						if(rows==undefined){
							$.messager.show({title:'温馨提示',msg:'请选择要修改的数据...',timeout:2000,showType:'slide'});
						}else{
							op="updateJdBaseInfo";
							if(editRow!=undefined){
								datagrid.datagrid("rejectChanges");
								datagrid.datagrid('endEdit', editRow);
								editRow=undefined;
							}
							
							if(editRow==undefined){
								var index=datagrid.datagrid("getRowIndex",rows);
								datagrid.datagrid('updateRow',{index:index,row:rows});
								datagrid.datagrid("beginEdit",index);
								editRow=index;
							}
						}
					}
				},'-',{
			    	text:'撤销',
					iconCls: 'icon-redo',
					handler: function(){
						datagrid.datagrid("rejectChanges");
						datagrid.datagrid('endEdit', editRow ); 
						editRow=undefined;
					}
				},'-',{
			    	text:'保存',
					iconCls: 'icon-save',
					handler: function(){
						datagrid.datagrid('endEdit',editRow); 
						var rows=datagrid.datagrid("getChanges")[0];
						if(rows==undefined){
							datagrid.datagrid("rejectChanges");
							datagrid.datagrid("unselectAll");
							editRow=undefined;
						}else{
							rows["op"]=op;
							
							$.post("../jdBaseInfoServletBack?t="+new Date(),rows,function(data){
								data=parseInt( $.trim(data) );
								if(data>0){
									$.messager.show({title:'成功提示',msg:'景点基本信息添加成功...',timeout:3000,showType:'slide'});
								}else{
									$.messager.alert('失败提示','商品信息添加失败，请稍后重试...','error');
								}
								rows=null;
								datagrid.datagrid("reload");
								editRow=undefined;
								datagrid.datagrid("rejectChanges");
								datagrid.datagrid("unselectAll");
							});
						}
					}
				}]
			}); 
				
			$("#jdBaseInfo_data").datagrid('getPager').pagination({
				beforePageText:'第',
				afterPageText:'页 共{pages}页',
				displayMsg:'当前显示{from}-{to} 条记录 共{total} 条记录'
			});
	
		},"json")
	}) 
</script>



